var ProjectOne = undefined;
var ProjectTwo = undefined;
var ProjectThree = undefined;
var versionslistModuleID = [];
var versionslistModuleDetalis = [];
var versionslistFeedDetalis = [];
var descriptionMsgData = [];
var firstProductID = '';
var firstProductFlag = true;
var secondProductFlag = true;
var OSProductID = undefined;
var AllProductID = undefined;
var OSProductVersionStatus = false;
var clickNewProduceStatus = false;

$(document).ready(function () {
    searchUserList();
    initClickProduct();
});
function initClickProduct(){
    var ProductID = $("#iframe",parent.document).attr("name");
    if(ProductID != undefined && ProductID != ""){
        firstProductFlag = false;
        secondProductFlag = false;
        OSProductVersionStatus = true;
        OSProductID = ProductID;
        $("#iframe",parent.document).attr("name","");
        doGetAllProducts('productPackUp', 'backLogProducts', 'productUnfurled');
    }else{
        doGetAllProducts('productPackUp', 'backLogProducts', 'productUnfurled');
    }
}
function doGetAllProducts(OneElement, TwoElement, ThreeElement) {
    $.post("doGetAllProducts", function (result) {
        if (result.state == 1) {
            var list = result.data;
            var backLogProducts = $("#backLogProducts");
            backLogProducts.empty();
            var $div = "";
            firstProductID = list[0].productId;
            for (var i in list) {
                $div += '<div class="productList">' +
                    '<div class="productLabel">' + (list[i].productName.substring(0, 1)) + '</div> ' +
                    '<div id="productInput'+ list[i].productId+'" class="productInput" hidden="hidden">' +
                    '<input value="'+list[i].productName+'" />' +
                    '    <button class="confirmBtn" onclick="updateProduct(\'' + list[i].productId + '\',\'product' + list[i].productId + '2\',\'' + list[i].productName + 'arrow2\',\'Yes\')">确定</button>'+
                    '<button class="cancelBtn" onclick="cancelUpdate(\'productInput'+ list[i].productId+'\',\'product' + list[i].productId + '2\',\'' + list[i].productName + 'arrow1\')">取消</button>'+
                    '</div>'+
                    ' <span id="product' + list[i].productId + '2" class="productName commonBlueFont" onMouseOver="mmigration(\'product' + list[i].productId + '2\')" onMouseOut="shiftOut()"' +
                    ' onclick="doGetProductVersion(\'' + list[i].productId + '\',\'' + list[i].productName + 'arrow1\', \'' + list[i].productName + '\', \'' + list[i].productId + '\')">' + list[i].productName + '</span>' +
                    ' <span id="product' + list[i].productId + '" class="productName commonBlueFont" hidden="hidden" onMouseOver="mmigration(\'product' + list[i].productId + '\')" onMouseOut="shiftOut()"' +
                    ' onclick="toCloseVersion(\'' + list[i].productId + '\',\'' + list[i].productName + 'arrow2\', \'' + (list[i].productId+2) + '\')">' + list[i].productName + '</span>' +
                    '<img class="commonBlueFont" id="' + list[i].productName + 'arrow1" src="../PM/images/arrow1.png" onMouseOver="mmigration(\'' + list[i].productName + 'arrow1\')" onMouseOut="shiftOut()"' +
                    '  onclick="showManangeModel(\'' + list[i].productId + '\',\'' + list[i].productName + 'arrow1\', \'' + list[i].productName + '\', \'' + list[i].productId + '\', \'' + list[i].productName + 'arrow2\')" /> ' +
                    '<img class="commonBlueFont"  id="' + list[i].productName + 'arrow2" src="../PM/images/arrow2.png"  hidden="hidden" onMouseOver="mmigration(\'' + list[i].productName + 'arrow2\')" onMouseOut="shiftOut()"' +
                    ' onclick="toCloseVersion(\'' + list[i].productId + '\',\'' + list[i].productName + 'arrow2\', \'' + list[i].productId + '2\')"/> ' +
                    '<div class="manangeProduct hoverPointer" id="manangeProduct'+ list[i].productId+'" hidden="hidden"><p onclick="updateProduct(\'' + list[i].productId + '\',\'product' + list[i].productId + '2\',\'' + list[i].productName + 'arrow2\')">编辑</p>' +
                    '<p style="border-top:1px solid #ccc;" onclick="deleteProduct(\'' + list[i].productId + '\')">删除</p></div>'+
                    '<div class="productEditions" id="productEditions' + list[i].productId + '"></div></div>';
            }
            backLogProducts.append($div);
            ProjectOne = OneElement;
            ProjectTwo = TwoElement;
            ProjectThree = ThreeElement;
            $("#" + ThreeElement).hide();
            $('#' + OneElement).show();
            $('#' + TwoElement).show();
        } else {
            showMessage("查询失败");
        }
        if(firstProductFlag){
            getFirstMsg();
        }
        if (OSProductID != undefined && OSProductID !="") {
            $("#product"+OSProductID+"2").click();
            firstProductFlag = true;
        }
    });
}
function cancelUpdate(updateProductID,productNameID,ImageID) {
    $("#"+updateProductID).hide();
    $("#"+productNameID).show();
    $("#"+ImageID).show();
}
function showManangeModel(productId,hideImage, productName, num,showImage){
    $(".manangeProduct").hide();
    $("#"+hideImage).hide();
    $("#"+showImage).show();
    $("#manangeProduct"+productId).show();
}
function getFirstMsg() {
    $("#backLogProducts .productList").first().find('span').first().click();
}
function getSecondMsg() {
    $("#productEditions" + firstProductID).first().find('p').first().click();
}
function updateProduct(productID,hideProductName,hideImage,state) {
    if(state == "Yes"){
        var ProductName = $("#productInput"+productID+">input").val();
        console.log("ProductName: "+ProductName);
        $.post("doUpdateProductName", {"ProductId": productID,"ProductName":ProductName}, function (result) {
            if(result.state == "Success"){
                showMessage("修改成功");
                doGetAllProducts('productPackUp', 'backLogProducts', 'productUnfurled');
            }else{
               showMessage("修改产品名称失败");
            }
        })
    }else{
        $("#productInput"+productID).show();
        $("#"+hideProductName).hide();
        $("#"+hideImage).hide();
        $(".manangeProduct").hide();
    }
}
function deleteProduct(productID){
    showMessage("确定要删除吗?","1","deleteProduct(\'"+productID+"\','Yes')");
}
function toClose(OneElement, TwoElement, ThreeElement) {
    $("#" + ThreeElement).hide();
    $("#" + TwoElement).hide();
    $("#" + OneElement).show();
}

function clickNewProduceVersion(productId) {
    $.post("doGetProductVersions", {"productId": productId}, function (result) {
        if (result.state == 1) {
            var list = result.data;
            if(list.length > 0){
                $("#edition" + list[list.length - 1].productVersionID).click();
            }else{
                $("#product",parent.document).click();
            }
        } else {
            showMessage("跳转失败");
        }
    });
}

function doGetProductVersion(productId, OneElement, productName, num) {
    var $Id = OneElement;
    var $Id2 = $Id.substr(0, $Id.length - 1) + "2";
    var $div = $("#productEditions" + productId);
    $(".manangeProduct").hide();
    $($div).show();
    $($div).empty();
    var params = {"productId": productId};
    $.post("doGetProductVersions", params, function (result) {
        if (result.state == 1) {
            var list = result.data;
            var $p = '';
            for (var i in list) {
                $p += "<p class='edition commonBlueFont' id='edition" + list[i].productVersionID + "' onMouseOver=\"mmigration(\'edition" + list[i].productVersionID + "\')\" onMouseOut=\"shiftOut()\"" +
                    " onclick=\"versionsMessage(\'" + list[i].productVersionID + "\', \'" + list[i].productVersionName + "\', \'" + productId + "\', \'" + productName + "\')\">" + list[i].productVersionName + "</p>";
            }
            $p += "<p class='commonBlueFont' id='addVersionsAssignmentLast' onMouseOver=\"mmigration(\'addVersionsAssignmentLast\')\" onMouseOut=\"shiftOut()\" " +
                "onclick=\"addVersionsAssignment(\'" + productId + "\', \'" + productName + "\', '', '','', 'save')\">添加版本</p>";
            $div.append($p);
            $("#" + OneElement).hide();
            $("#" + $Id2).show();
        } else {
            showMessage("查询失败");
        }
        if (secondProductFlag) {
            getSecondMsg();
            secondProductFlag = false;
        }
        if (clickNewProduceStatus) {
            clickNewProduceVersion(AllProductID);
            AllProductID = undefined;
            clickNewProduceStatus = false;
        }
        if(OSProductVersionStatus){
            $("#product"+OSProductID+"").parent().children().find("#addVersionsAssignmentLast").click();
            $("#iframe",parent.document).attr("name","initAddVersion");
            OSProductID = undefined;
            OSProductVersionStatus = false;
        }


        $("#product" + num).show();
        $("#product" + num).css("hidden",false);
        $("#product" + num + "2").hide();
    });
}

function addNewProject() {
    $("#projectNewName").val('');
    $("#showProjectMsg").show();
}

function addNewProjectSure() {
    $.ajax({
        url: "saveNewProject",
        type: 'post',
        dataType: 'json',
        data: {
            "ProductName": $("#projectNewName").val(),
        },
        success: function (data) {
            var result = data && data.result;
            if (result == "Success") {
                doGetAllProducts(ProjectOne, ProjectTwo, ProjectThree);
                $("#showProjectMsg").hide();
                showMessage("添加成功");
            } else if (result == "NotFound") {
                showMessage("添加失败");
            }
        }, error: function (data) {
            showMessage("添加失败");
        },
        timeout: function (data) {
            showMessage("添加超时");
        }
    })
}

function toCloseVersion(productId, OneElement, num) {
    var $Id = OneElement;
    $("#" + OneElement).hide();
    var $Id2 = $Id.substr(0, $Id.length - 1) + "1";
    $("#" + $Id2).show();
    var $div = $("#productEditions" + productId);
    $($div).hide();
    $("#product" + productId).hide();
    $("#manangeProduct" + productId).hide();
    $("#product" + num).show();
}

function addVersionsAssignment(productID, productName, versionsID, versionsName, productVersionMsg, flag) {
    if (flag == "save") {
        $("#newVersionsName").val('');
        $("#newVersions").val('');
        $("#sureAddVersions").attr("onclick", "sureAddVersions(\'" + productID + "\',\'" + productName + "\', '', '',\'" + flag + "\')");
        $("#BackLogRightMenu").hide();
        $("#addVersionsDiv").show();
    } else if (flag == "update") {
        $("#newVersionsName").val(versionsName);
        $("#newVersions").val(productVersionMsg);
        $("#totleMsg2").html($("#totleMsg").html());
        $("#fulfillDay2").html($("#fulfillDay").html());
        $("#residueDay2").html($("#residueDay").html());
        $("#sureAddVersions").attr("onclick", "sureAddVersions(\'" + productID + "\',\'" + productName + "\',\'" + versionsID + "\',\'" + versionsName + "\',\'" + flag + "\')");
        $("#BackLogRightMenu").hide();
        $("#addVersionsDiv").show();
    }
}

function delVersionsAssignment(productId, productName, versionsId) {
    $.ajax({
        url: "delVersionsMsg",
        type: 'post',
        dataType: 'json',
        data: {
            "ProductID": productId,
            "ProductVersionID": versionsId,
        },
        success: function (data) {
            var result = data && data.result;
            if (result == "Success") {
                AllProductID = productId;
                clickNewProduceStatus = true;
                doGetProductVersion(productId, productName + 'arrow1', productName);
                InitVersionDivMsg();
                showHideModal();
                showMessage("删除成功");
            } else if (result == "NotFound") {
                showMessage("删除失败");
            }
        }, error: function (data) {
            showMessage("删除失败");
        },
        timeout: function (data) {
            showMessage("删除超时");
        }
    })
}

function closeAddModule(hideModel) {
    $("#" + hideModel).hide();
    var iframeName = $("#iframe",parent.document).attr("name");
    var productEditions = $(".productEditions p");
    if(iframeName == "initAddVersion"){
        $("#sprint",parent.document).click();
        $("#iframe",parent.document).attr("name","");
    }
    for (var i = 0; i < productEditions.length; i++) {
        if (productEditions[i].className.indexOf("fontBlue") >= 0) {
            $(productEditions[i]).click();
        }
    }
}
function InitVersionDivMsg() {
    $("#backLogFeedNumber").html("-");
    $("#productVersionMsg").html("这里是版本描述");
    $("#addVersionsDiv").hide();
    $("#BackLogRightMenu").show();
    $("#updateVersions").removeAttr("onclick");
    $("#deleteVersions").removeAttr("onclick");
    $("#toLoadMsg").html("0%");
    document.getElementById("toLoadMsg").style.width = 0 + "%";
    $("#totleMsg").html(0);
    $("#fulfillDay").html(0);
    $("#residueDay").html(0);
    $("#divAllMsg").html("");
}
function sureAddVersions(productID, productName, versionsID, versionsName, flag) {

    if (flag == "save") {
        $.ajax({
            url: "addVersionsMsg",
            type: 'post',
            dataType: 'json',
            data: {
                "ProductID": productID,
                "ProductVersionName": $("#newVersionsName").val(),
                "ProductVersionDescription": $("#newVersions").val(),
            },
            success: function (data) {
                var result = data && data.result;
                if (result == "Success") {
                    $("#addVersionsDiv").hide();
                    $("#BackLogRightMenu").show();
                    $("#BackLogRightMenu>div").show()
                    AllProductID = productID;
                    clickNewProduceStatus = true;
                    doGetProductVersion(productID, productName + 'arrow1', productName);
                    showMessage("添加成功");
                } else if (result == "NotFound") {
                    showMessage("添加失败");
                }
            }, error: function (data) {
                showMessage("添加失败");
            },
            timeout: function (data) {
                showMessage("添加超时");
            }
        })
    } else if (flag == "update") {
        $.ajax({
            url: "updateVersionsMsg",
            type: 'post',
            dataType: 'json',
            data: {
                "ProductID": productID,
                "ProductVersionID": versionsID,
                "ProductVersionName": $("#newVersionsName").val(),
                "ProductVersionDescription": $("#newVersions").val()
            },
            success: function (data) {
                var result = data && data.result;
                if (result == "Success") {
                    doGetProductVersion(productID, productName + 'arrow1', productName);
                    versionsMessage(versionsID, $("#newVersionsName").val(), productID, productName);
                    showMessage("修改成功");
                } else if (result == "NotFound") {
                    showMessage("修改失败");
                }
            }, error: function (data) {
                showMessage("修改失败");
            },
            timeout: function (data) {
                showMessage("修改超时");
            }
        })
    }
}

function versionsMessage(productVersionID, productVersionName, productID, productName) {
    $.ajax({
        url: "doGetProductModuleID",
        type: 'post',
        dataType: 'json',
        data: {
            "ProductID": productID,
            "ProductVersionID": productVersionID
        },
        success: function (data) {
            $("#BackLogRightMenu").show();
            $("#BackLogRightMenu>div").show();
            versionslistModuleID = data && data.listModuleID || [];
            descriptionMsgData = data.descriptionMsg || [];
            var ModuleIDList = '';
            var length = versionslistModuleID.length;
            if (length <= 0) {
                /*showMessage("没有查询到数据");*/
                $("#noData").show();
                $(".edition").removeClass("fontBlue");
                $("#edition" + productVersionID).addClass("fontBlue");
                InitVersionDivMsg();
                versionDetalisMsg(productVersionID, productVersionName, productID, productName, '');
            } else {
                $("#noData").hide();
                $("#addVersionsDiv").hide();
                $("#BackLogRightMenu").show();
                for (var i = 0; i < length; i++) {
                    if (length - 1 != i) {
                        ModuleIDList += versionslistModuleID[i].moduleID + ",";
                    } else {
                        ModuleIDList += versionslistModuleID[i].moduleID;
                    }
                }
                versionDetalisMsg(productVersionID, productVersionName, productID, productName, ModuleIDList);
            }
        },
        error: function (data) {
            showMessage("查询失败");
        },
        timeout: function (data) {
            showMessage("查询超时");
        }
    })
    doneEffect();
}

function versionDetalisMsg(productVersionID, productVersionName, productID, productName, ModuleIDList) {
    $(".edition").removeClass("fontBlue");
    $("#edition" + productVersionID).addClass("fontBlue");
    InitModuleStyle();
    $("#addModuleIDs").hide();
    $("#backLogFeedNumber").html(productName + "-" + productVersionName);
    $("#divAllMsg").html('');
    var divAllMsg = $("#divAllMsg");
    divAllMsg.empty();
    $.ajax({
        url: "getVersionDetalisMsg",
        type: 'post',
        dataType: 'json',
        data: {
            "ProductID": productID,
            "ProductVersionID": productVersionID,
            "ModuleIDList": ModuleIDList
        },
        success: function (data) {
            versionslistModuleDetalis = data && data.listModuleDetalis || [];
            versionslistFeedDetalis = data && data.listFeedDetalis || [];
            var ModuleMsgLength = versionslistModuleDetalis.length;
            var FeedMsgLength = versionslistFeedDetalis.length;
            var length = versionslistModuleID.length;
            $("#totleMsg").html(data.CountAllList || 0);
            $("#fulfillDay").html(data.SignAllList || 0);
            $("#residueDay").html(data.ErrandAllList || 0);
            if (data.SignAllList && data.CountAllList && data.SignAllList != 0 && data.CountAllList != 0) {
                document.getElementById("toLoadMsg").style.width = (((data.SignAllList / data.CountAllList) * 100).toFixed(2) || 0) + "%";
                $("#toLoadMsg").html((((data.SignAllList / data.CountAllList) * 100).toFixed(2) || 0) + "%");
            } else {
                document.getElementById("toLoadMsg").style.width = 0 + "%";
                $("#toLoadMsg").html(0 + "%");
            }
            $("#addVersionsDiv").hide();
            $("#BackLogRightMenu").show();
            $("#productVersionMsg").html(descriptionMsgData[0].productVersionDescription);
            $("#updateVersions").attr("onclick", "addVersionsAssignment(\'" + productID + "\',\'" + productName + "\',\'" + productVersionID + "\',\'" + productVersionName + "\',\'" + descriptionMsgData[0].productVersionDescription + "\', 'update')");
            $("#deleteVersions").attr('onclick', 'showMessage(\"确定要删除吗\",\"1\",\"delVersionsAssignment(\'' + productID + '\',\'' + productName + '\',\'' + productVersionID + '\')\")');
            if (length <= 0) {
                divAllMsg.append('<div class="col-sm-2 divMsg" id="addModuleIDs" hidden="hidden">' +
                    '<div class="col-sm-12">' +
                    '<input class="moduleInputTwo" name="addModuleID" id="addModuleID" value=""/>' +
                    '<span  id="addModuleSpan" style="margin-right: 8px;margin-left: 15px;;cursor:pointer;" onclick="addModule(\''
                    + productID + '\', \'' + productName + '\', \'' + productVersionID + '\', \'' + productVersionName + '\')">确定</span>' +
                    '<span style="margin-top: 2px;margin-right: 15px;" onclick="closeAddModule(\'addModuleIDs\')">取消</span>' +
                    '</div>' +
                    '<div class="col-sm-12">' +
                    '<select id="sprintPullDown" class="form-control">' +
                    '</select>' +
                    '<span class="marginRightTen">共: 0天</span>' +
                    '<span class="marginRightTen">已完成: 0天</span>' +
                    '<span>剩余: 0天</span>' +
                    '</div>' +
                    '<div class="col-sm-12" style="position: absolute; bottom: 10px">' +
                    '<u><span class="marginRight2Ten" id="addBackClick" style="color: #CCC;">添加back Log</span></u>' +
                    '<u><span id="addFeedClick" style="color: #CCC;">添加反馈</span></u>' +
                    '<a id="sprintNameSign">' + (sprintNameSign || "未知") + '</a>' +
                    '</div>' +
                    '</div>' +
                    '<div class="col-sm-2 divMsg" id="versionsModule" onclick="showAddModule(\'' + productVersionID + '\')">添加功能</div>');
            } else {
                var sprintNameSign = '';
                var deleteModel = '';
                for (var j = 0; j < length; j++) {
                    var workTypeName = ''
                    var divOneContent = '';
                    var divTwoContent = '';
                    var divThreeContent = '';
                    var divFourContent = '';
                    var backlogStatus = '';
                    var feedBackNum = 0;
                    var versionslistModule = versionslistModuleID[j];
                    if (versionslistModule.sprintName) {
                        sprintNameSign = versionslistModule.sprintNameSign;
                    }
                    deleteModel = "showMessage('确定要删除吗','1','deleteModule(\"" + j + "\",\"" + productID + "\",\"" + productName + "\",\"" + productVersionID + "\",\"" + productVersionName + "\",\"" + versionslistModule.moduleID + "\")')";
                    divOneContent = '<div class="col-sm-2 divMsg">' +
                        '<div class="col-sm-12"><span class="moduleSpan" id="moduleSpan' + j + '">' + (versionslistModule.moduleName || "未知") +
                        '</span><input class="moduleInput" name="moduleName' + j + '" id="moduleInput' + j + '" value="" hidden="hidden" />' +
                        '<span class="spanFloatAll spanFloat" id="spanFloatAll' + j + '"><span class="spanFloat" style="cursor: pointer" onclick=' + deleteModel + '>删除</span>' +
                        '<span class="spanFloat" style="cursor: pointer" onclick="updateModuleName(\'' + j + '\', \'' + (versionslistModule.moduleName || "未知") + '\')">修改</span></span>' +
                        '<span style="cursor: pointer" class="spanFloatSure spanFloat" id="spanFloatSure' + j + '" onclick="sureModuleName(\'' + j + '\', \'' + productID + '\', \'' + productName + '\', \'' + productVersionID + '\', \'' + productVersionName + '\', \'' + versionslistModule.moduleID + '\')" hidden="hidden">确定</span>' +
                        '</div>' +
                        '<div  class="col-sm-12" style="padding-right: 15px;">' +
                        '<div class="col-sm-12 progress progressDiv toLoadDiv">' +
                        '<div class="progress-bar progress-bar-info toLoadMsg" role="progressbar" id="toLoadMsg' + j + '" aria-valuenow="20" aria-valuemin="0" aria-valuemax="100" style="width:0%">0%</div>' +
                        '</div>' +
                        '</div>' +
                        '<div class="col-sm-12">' +
                        '<span class="marginRightTen">共: <span id="totleMsgs' + j + '">0</span>天</span>' +
                        '<span class="marginRightTen">已完成: <span id="fulfillDays' + j + '">0</span>天</span>' +
                        '<span>剩余: <span id="residueDays' + j + '">0</span>天</span>' +
                        '</div>'
                    ;
                    for (var i = 0; i < ModuleMsgLength; i++) {
                        var ModuleDetalis = versionslistModuleDetalis[i];
                        if (ModuleDetalis.moduleID == versionslistModule.moduleID) {
                            if (ModuleDetalis.workTypeName != workTypeName) {
                                divTwoContent = '<div class="col-sm-12 divWorkTitle">' + (ModuleDetalis.workTypeName || "未知") + '</div>';
                                workTypeName = ModuleDetalis.workTypeName;
                            } else {
                                divTwoContent = '';
                            }
                            divFourContent += divTwoContent + '<div class="col-sm-12">' +
                                '<span class="marginRightTen">' + (ModuleDetalis.backLogName || 0) + '</span>' +
                                '<span class="marginRightTen">' + (ModuleDetalis.userName || "未知人") + '</span>' +
                                '<a class="marginRightTen">' + (ModuleDetalis.expectedWorkDate || 0) + '天</a>' +
                                '<span class="marginRightTen">' + (ModuleDetalis.stateName || "未知") + '</span>' +
                                '</div>';
                        }
                    }
                    divThreeContent = '';
                    var onOffFeed = '';
                    feedBackNum = 0;
                    for (var i = 0; i < FeedMsgLength; i++) {
                        var FeedMsg = versionslistFeedDetalis[i];
                        if (FeedMsg.moduleID == versionslistModule.moduleID) {
                            feedBackNum += 1;
                            if (onOffFeed == '') {
                                divThreeContent = '<div class="col-sm-12">反馈</div>';
                                onOffFeed = "no";
                            }
                            divThreeContent +=
                                '<div class="col-sm-12"> ' +
                                '<span>' + feedBackNum + '.</span> ' +
                                '<span class="marginRightTen">' + (FeedMsg.feedBackDescription || '未知反馈内容') + '</span> ' +
                                '<span class="marginRightTen">' + (FeedMsg.userName || '未知') + '</span> ' +
                                '</div> ';
                        }
                    }
                    var addLogOrFeedback =
                        '<div class="col-sm-12">' +
                        '<u><span class="marginRight2Ten" style="cursor: pointer" onclick="addBackLogMsg(\'' + j + '\', \'' + productID + '\', \'' + productName + '\', \'' + productVersionID + '\', \'' + productVersionName + '\', \'' + versionslistModule.moduleID + '\', \'' + versionslistModule.moduleName + '\')">添加back Log</span></u>' +
                        '<u><span style="cursor: pointer" onclick="addFeedBackMsg(\'' + j + '\', \'' + productID + '\', \'' + productName + '\', \'' + productVersionID + '\', \'' + productVersionName + '\', \'' + versionslistModule.moduleID + '\', \'' + versionslistModule.moduleName + '\')">添加反馈</span></u>' +
                        '<a id="sprintNameSign">' + (sprintNameSign || "未知") + '</a>' +
                        '</div>';
                    divAllMsg.append(divOneContent + "<div class='col-sm-12 proStyle'>" + divFourContent + divThreeContent + "</div>" + addLogOrFeedback);
                    if (j == length - 1) {
                        divAllMsg.append('<div class="col-sm-2 divMsg" id="addModuleIDs" hidden="hidden">' +
                            '<div class="col-sm-12">' +
                            '<input class="moduleInputTwo" name="addModuleID" id="addModuleID" value=""/>' +
                            '<span  id="addModuleSpan" style="margin-right: 8px;margin-left:15px;;cursor:pointer;" onclick="addModule(\''
                            + productID + '\', \'' + productName + '\', \'' + productVersionID + '\', \'' + productVersionName + '\', \'' + versionslistModule.moduleID + '\')">确定</span>' +
                            '<span  style="margin-top: 2px;margin-right: 15px;" onclick="closeAddModule(\'addModuleIDs\')">取消</span>' +
                            '</div>' +
                            '<div class="col-sm-12">' +
                            '<select id="sprintPullDown" class="form-control">' +
                            '</select>' +
                            '<span class="marginRightTen">共: 0天</span>' +
                            '<span class="marginRightTen">已完成: 0天</span>' +
                            '<span>剩余: 0天</span>' +
                            '</div></div>' +
                            '<div class="col-sm-2 divMsg" id="versionsModule" onclick="showAddModule(\'' + productVersionID + '\')">添加功能</div>');
                    }
                    if (data.SignList) {
                        $("#totleMsgs" + j).html(data.SignList[j][0] || 0);
                        $("#fulfillDays" + j).html(data.SignList[j][1] || 0);
                        $("#residueDays" + j).html(data.SignList[j][2] || 0);
                        if (data.SignList[j][1] && data.SignList[j][0] && data.SignList[j][1] != 0 && data.SignList[j][0] != 0) {
                            document.getElementById("toLoadMsg" + j).style.width = ((data.SignList[j][1] / data.SignList[j][0]) * 100).toFixed(2) + "%";
                            document.getElementById("toLoadMsg" + j).innerHTML = ((data.SignList[j][1] / data.SignList[j][0]) * 100).toFixed(2) + "%";
                        } else {
                            document.getElementById("toLoadMsg" + j).style.width = 0 + "%";
                        }

                    }
                }
            }
        },
        error: function (data) {
            showMessage("查询失败");
        },
        timeout: function (data) {
            showMessage("查询超时");
        }
    })
}

function updateModuleName(Index, moduleName) {
    InitModuleStyle();
    $("#moduleInput" + Index).val(moduleName);
    $("#moduleSpan" + Index).hide();
    $("#moduleInput" + Index).show();
    $("#spanFloatAll" + Index).hide();
    $("#spanFloatSure" + Index).show();
}

function addBackLogMsg(Index, productID, productName, productVersionID, productVersionName, moduleID, moduleName) {
    document.getElementById("addBackLogMsgForm").reset();
    selectDate("expectStart");
    selectDate("expectEnd");
    $("#addBackLogTitle").html(moduleName);
    $("#addBackLogMsgSure").attr("onclick", "addBackLogSure(\'" + Index + "\',\'" + productID + "\',\'" + productName + "\',\'" + productVersionID + "\',\'" + productVersionName + "\',\'" + moduleID + "\')");
    $(".addBackLog").show();
}

function addFeedBackMsg(Index, productID, productName, productVersionID, productVersionName, moduleID, moduleName) {
    document.getElementById("addFeedBackMsgForm").reset();
    $("#addFeedBackTitle").html(moduleName);
    $("#addFeedBackMsgSure").attr("onclick", "addFeedBackSure(\'" + Index + "\',\'" + productID + "\',\'" + productName + "\',\'" + productVersionID + "\',\'" + productVersionName + "\',\'" + moduleID + "\')");
    $(".addFeedBack").show();
}

function hideBackLogMsg() {
    document.getElementById("addBackLogMsgForm").reset();
    document.getElementById("addFeedBackMsgForm").reset();
    $("#addBackLogMsgSure").removeAttr("onclick");
    $("#addFeedBackMsgSure").removeAttr("onclick");
    $(".addBackLog").hide();
    $(".addFeedBack").hide();
}
function promptResult(InputID) {
    var InputID = $("#"+InputID).val();
    if(InputID % 1 != 0){
        showMessage("请输入整数");
    }
}
function addBackLogSure(Index, productID, productName, productVersionID, productVersionName, moduleID) {

    var workName = $("#workName").val();
    var expectDay = $("#expectDay").val();
    var expectStartDay = $("#expectStartDay").val();
    var expectEndDay = $("#expectEndDay").val();
    var workPerson = $("#workPerson").val();
    var days = datedifference(expectEndDay,expectStartDay);

    if(workName =="" || workName == undefined){
        showMessage("工作名称不能为空");
        return;
    }
    if(workPerson == "" || workPerson == undefined){
        showMessage("工作成员不能为空");
        return;
    }
    if(expectDay == "" || expectDay == undefined){
        showMessage("预期天数不能为空");
        return;
    }
    if(expectStartDay == "" || expectStartDay == undefined){
        showMessage("开始时间不能为空");
        return;
    }
    if(expectEndDay == "" || expectEndDay == undefined){
        showMessage("结束时间不能为空");
        return;
    }
    if(expectDay % 1 != 0){
        showMessage("预期天数只能输入整数");
        return;
    }
    if(Date.parse(expectEndDay) < Date.parse(expectStartDay)){
        showMessage("结束日期不能小于开始时间");
        return;
    }
    if(days == 0){
        days = 1;
    }
    if(days != expectDay){
        showMessage("选择的时间与预期时间不一致");
        return;
    }
    $.ajax({
        url: "addBackLogMsgSure",
        type: 'post',
        dataType: 'json',
        data: {
            "ModuleID": moduleID,
            "BackLogStatus": 1,
            "WorkTypeID": $("input[name='workType']:checked").val(),
            "BackLogName": $("#workName").val(),
            "UserID": $("#workPerson").val(),
            "ExpectedWorkDate": parseInt($("#expectDay").val()),
            "ExpectedStartDTTM": stringToDate($("#expectStartDay").val()),
            "ExpectedEndDTTM": stringToDate($("#expectEndDay").val()),
        },
        success: function (data) {
            var result = data && data.result;
            if (result == "Success") {
                doGetProductVersion(productID, productName + 'arrow1', productName);
                versionsMessage(productVersionID, productVersionName, productID, productName);
                $("#addBackLogMsgSure").removeAttr("onclick");
                $(".addBackLog").hide();
                showMessage("添加成功");
                $.post("sendWorkDataByUserID", {"UserID": $("#workPerson").val()}, function (result) {
                })
            } else if (result == "NotFound") {
                showMessage("添加失败");
            }
        }, error: function (data) {
            showMessage("添加失败");
        },
        timeout: function (data) {
            showMessage("添加超时");
        }
    })
}

function addFeedBackSure(Index, productID, productName, productVersionID, productVersionName, moduleID) {
    $.ajax({
        url: "addFeedBackMsgSure",
        type: 'post',
        dataType: 'json',
        data: {
            "ModuleID": moduleID,
            "FeedBackStatus": 0,
            "FeedBackDescription": $("#FeedBackMsg").val()
        },
        success: function (data) {
            var result = data && data.result;
            if (result == "Success") {
                doGetProductVersion(productID, productName + 'arrow1', productName);
                versionsMessage(productVersionID, productVersionName, productID, productName);
                $("#addFeedBackMsgSure").removeAttr("onclick");
                $(".addFeedBack").hide();
                showMessage("添加成功");
            } else if (result == "NotFound") {
                showMessage("添加失败");
            }
        }, error: function (data) {
            showMessage("添加失败");
        },
        timeout: function (data) {
            showMessage("添加超时");
        }
    })
}

function sureModuleName(Index, productID, productName, productVersionID, productVersionName, moduleID) {
    $.ajax({
        url: "updateModuleName",
        type: 'post',
        dataType: 'json',
        data: {
            "ModuleID": moduleID,
            "ProductVersionID": productVersionID,
            "ModuleName": $("#moduleInput" + Index).val(),
        },
        success: function (data) {
            var result = data && data.result;
            if (result == "Success") {
                doGetProductVersion(productID, productName + 'arrow1', productName);
                versionsMessage(productVersionID, productVersionName, productID, productName);
                showMessage("修改成功");
            } else if (result == "NotFound") {
                showMessage("修改失败");
            }
        }, error: function (data) {
            showMessage("修改成功");
        },
        timeout: function (data) {
            showMessage("修改超时");
        }
    })
}

function showAddModule(productVersionID) {
    $("#sprintPullDown").empty();
    $.post("doGetAllSprint", {"productVersionID": productVersionID}, function (result) {
        if (result.state == 1) {
            var list = result.data;
            if (list.length > 0) {
                $("#addModuleIDs").show();
                for (var i = 0; i < list.length; i++) {
                    $("#sprintPullDown").append("<option value='" + list[i].sprintID + "'>" + list[i].sprintName + "</option>");
                }
            } else {
                showMessage("sprint数据为空,请先添加sprint", "1", "toAddSprint(\'" + productVersionID + "\')");
            }
        } else {
            showMessage("查询失败");
        }
    });
}

function searchUserList() {
    $.post("doGetAllMembers", function (result) {
        if (result.state == 1) {
            var list = result.data;
            for (var i = 0; i < list.length; i++) {
                $("#workPerson").append("<option value='" + list[i].userID + "'>" + list[i].userName + "</option>");
            }
        } else {
            showMessage("查询失败");
        }
    });
}

function addModule(productID, productName, productVersionID, productVersionName, moduleID) {
    var addModuleID = $("#addModuleID").val();
    if(addModuleID == "" || addModuleID == undefined){
        showMessage("功能模块名称不能为空");
        return;
    }
    var options = $("#sprintPullDown option");
    var SprintID = '';
    for (var i = 0; i < options.length; i++) {
        if (options[i].selected == true) {
            SprintID = options[i].value;
        }
    }
    console.log("SprintID： "+SprintID);
    $.ajax({
        url: "addModuleID",
        type: 'post',
        dataType: 'json',
        data: {
            "ModuleName": $("#addModuleID").val(),
            "ProductVersionID": productVersionID,
            "SprintID": SprintID
        },
        success: function (data) {
            var result = data && data.result;
            if (result == "Success") {
                doGetProductVersion(productID, productName + 'arrow1', productName);
                $("#addModuleIDs").hide();
                versionsMessage(productVersionID, productVersionName, productID, productName);
                InitModuleStyle();
                showMessage("添加成功");
            } else if (result == "NotFound") {
                showMessage("添加失败");
            }
        }, error: function (data) {
            showMessage("添加成功");
        },
        timeout: function (data) {
            showMessage("添加超时");
        }
    })
}

function deleteModule(Index, productID, productName, productVersionID, productVersionName, moduleID) {
    $.ajax({
        url: "deletModuleID",
        type: 'post',
        dataType: 'json',
        data: {
            "ModuleID": moduleID,
            "ProductVersionID": productVersionID
        },
        success: function (data) {
            var result = data && data.result;
            if (result == "Success") {
                doGetProductVersion(productID, productName + 'arrow1', productName);
                versionsMessage(productVersionID, productVersionName, productID, productName);
                InitModuleStyle();
                showHideModal();
                showMessage("删除成功");
            } else if (result == "NotFound") {
                showMessage("删除失败");
            }
        }, error: function (data) {
            showMessage("删除失败");
        },
        timeout: function (data) {
            showMessage("删除超时");
        }
    })
}

function InitModuleStyle() {
    $(".moduleSpan").show();
    $(".moduleInput").hide();
    $(".spanFloatAll").show();
    $(".spanFloatSure").hide();
}

function selectDate(ID, minView, pickerPosition, startView) {
    $('#' + ID).datetimepicker({
        language: 'zh-CN', // String. 默认值: 'en'
        weekStart: 1, // Integer. 默认值：0;一周从哪一天开始。0（星期日）到6（星期六）
        todayBtn: "linked", // Boolean, "linked". 默认值: false;
        todayHighlight: true, // Boolean. 默认值: false;如果为true, 高亮当前日期。
        autoclose: true, // Boolean. 默认值：false;当选择一个日期之后是否立即关闭此日期时间选择器。
        startView: startView == undefined ? 2 : startView, // Number, String. 默认值：2, 'month';日期时间选择器打开之后首先显示的视图。[0/'hour',1/'day',2/'month',3/'year',4/'decade']
        minView: minView == undefined ? 2 : minView, // Number, String. 默认值：0, 'hour';日期时间选择器所能够提供的最精确的时间选择视图。
        forceParse: true, // Boolean. 默认值: true;当选择器关闭的时候，是否强制解析输入框中的值
        pickerPosition: pickerPosition || 'bottom-left', // String. 默认值: 'bottom-right';通过设置选项可以讲选择器放倒输入框下方
    });
}

function stringToDate(date, symbol) {
    if (date.length <= 10) {
        if (!symbol) {
            symbol = "-";
        }
        var array = date.split(symbol);
        return new Date(array[0], array[1] - 1, array[2]);
    } else {
        var array = date.split(/[^0-9]/ig);
        return new Date(array[0], array[1] - 1, array[2], array[3] || 0, array[4] || 0, array[5] || 0);
    }
}

function mmigration(ID) {
    $(".commonBlueFont").removeClass("fontComClass");
    $("#" + ID).addClass("fontComClass");
}

function shiftOut() {
    $(".commonBlueFont").removeClass("fontComClass");
}

function hideProMsg() {
    $("#projectNewName").val('');
    $("#showProjectMsg").hide();
}